package pc;

import my_stream.ArraryList;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class random_name {
    public static void main(String[] args) throws IOException {
        ArrayList<Student> list = new ArrayList<>();
        //假设文件中的格式为：名字-性别-年龄-权重
        BufferedReader br = new BufferedReader(new FileReader(""));
        String s;
        while((s=br.readLine())!=null){
            String [] arr = s.split("-");
            Student stu = new Student(arr[0],  arr[1],
                    Integer.parseInt(arr[2]), Double.parseDouble(arr[3]));
            list.add(stu);
        }
        br.close();
        double w = 0;
        double []arr = new double[list.size()];
        //总合
        for(Student stu : list){
            w = stu.getW() + w;
        }
        //每人
        int index = 0;
        for(Student stu : list){
            arr[index] = stu.getW() / w;
            index++;
        }
        //分类
        for(int i =1;i<arr.length;i++){
            arr[i] += arr[i-1];
        }

        double num = Math.random();
        int x = -Arrays.binarySearch(arr, num) - 1;

        //修改权重
        w = list.get(x).getW() / 2;
        list.get(x).setW(w);
        //将数据写入文件中

    }
}
